package cn.itrip.biz.controller;

import cn.itrip.beans.dto.Dto;
import cn.itrip.beans.pojo.ItripLabelDic;
import cn.itrip.beans.vo.ItripLabelDicVO;
import cn.itrip.common.DtoUtil;
import cn.itrip.common.EmptyUtils;
import cn.itrip.common.ErrorCode;
import cn.itrip.dao.service.ItripLabelService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Tequila
 **/
@CrossOrigin
@RequestMapping("/biz/api/hotel")
@RestController
public class ItripLabelController {

    // 注入service
    @Autowired
    private ItripLabelService itripLabelService;

    @GetMapping("/queryhoteldetails/{hotelId}")
    public Dto queryHotelDetails(@PathVariable Integer hotelId){
        try {
            if (EmptyUtils.isNotEmpty(hotelId)){

               List<ItripLabelDicVO> list =  itripLabelService.queryHotelDetails(hotelId);
               return DtoUtil.returnDataSuccess(list);

            }else{
                return DtoUtil.returnFail("酒店id不能为空",ErrorCode.PARAM_ISNULL);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("系统异常",ErrorCode.SYSTEM_ERROR);
        }
    }
    @GetMapping("/queryhotelfeature")
    public Dto queryHotelFeature(){
        Map<String,Object> map = new HashMap<>();
        map.put("parentId",16);
        List<ItripLabelDicVO> voList = new ArrayList<>();
        // 去数据库查询特色列表
        try {
            List<ItripLabelDic> itripLabelDicList = itripLabelService.queryHotelFeature(map);
            // 查询到列表之后 返回后数据  将数据装入vo中减少io 压力
            // BeanUtils:作用将对象中的数据 转移到另一个对象 前提条件名字一样
            for (ItripLabelDic itripLabelDic : itripLabelDicList) {
                ItripLabelDicVO vo = new ItripLabelDicVO();
                BeanUtils.copyProperties(itripLabelDic,vo);
                // 添加到列表
                voList.add(vo);
            }
        }catch (Exception e){
            return DtoUtil.returnFail("系统错误,请重试!", ErrorCode.SYSTEM_ERROR);
        }
        // 统一返回数据
       return  DtoUtil.returnDataSuccess(voList);
    }
}
